class GetDeviceInfo {
    data: any
    constructor(data: any) {

        this.data = data

    }

    getProjectNameList() {

        let projectNameList = [{
            "id": -1,
            "projectName": "全部项目",
            "fid": -1

        }]
        for (let i in this.data) {
          //  if (this.data[i].type === 1) {
                projectNameList.push(this.data[i])
          //  }
        }
        return projectNameList
    }

    getDeviceList(id: Number) {
        let DeviceList = []
        // //console.log(id);
        for (let i in this.data) {
            //if (this.data[i].fid == id || (this.data[i].type == 2 && id == -1)) {
                DeviceList.push(this.data[i])
           // }
        }
        return DeviceList
    }

}

class ProjectData {
    data: any
    fid: any
    constructor(data: any, fid: any) {
        this.data = data
        this.fid = fid
    }

    getOnlineDev() {
        let out = [{ value: 0, name: '在线' },
        { value: 0, name: '离线' },]
        this.data.map((i: { fid: number; offline: number; online: number }) => {
            if ((i.fid == this.fid || this.fid == -1)) {
              if(i.hasOwnProperty('offline')){
                out[1].value += i.offline
              }
              if(i.hasOwnProperty('online')){
                out[0].value += i.online
              }
            }

        })
        return out
    }

    getOtherInfo() {
        let out: any = {
            "当月电量": 0,
            "当月省电": 0,
            "当月节能率": 0,
            "减少碳排放": 0,
            "节约标准煤": 0,
            "减少二氧化硫": 0,
            "running_time": 0
        }
        this.data.map((i: {
            product_id: any, fid: number; power: number; running_time: number
        }) => {

            if (i.product_id == this.fid || this.fid == -1) {
                out.当月电量 += i.power
                out.running_time += i.running_time | 0
            }

        })
        out.当月省电 = (out.running_time * 20 - out.当月电量)//20w
        out.当月节能率 = (1 - out.当月电量 / (out.running_time * 20)) * 100 | 0
        out.减少碳排放 = out.当月省电 * 0.272
        out.节约标准煤 = out.当月省电 * 0.4
        out.减少二氧化硫 = out.当月省电 * 0.03
        for (const iterator in out) {

            if (iterator === "当月节能率" || iterator === "running_time") {
                out[iterator] = out[iterator].toFixed(3)

            } else {
                out[iterator] = (out[iterator] / 1000).toFixed(3)
            }

        }
        return out
    }


}


const report = (data: any[]) => {
    let self = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    let others = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    data.map(i => {
        self[i.month - 1] += i.power / 1000
        others[i.month - 1] += i.running_time * 20 / 1000
    })

    return [self, others]
}

const report3 = (data: any[]) => {
    let self = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    let others = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

    data.map(i => {
        self[i.month - 1] += i.power
        others[i.month - 1] += i.running_time * 20 / 1000
    })

    return [self, others]
}



const report2 = (data: any[], currtMonth:any) => {
    //console.log('data', data);
    let self = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    let others = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    data.map(i => {
        if (i.day&&i.month==currtMonth) {
            self[i.days - 1] += i.dayPower / 1000
            others[i.days - 1] += i.running_time * 20 / 1000
        }
    })
    return [self, others]
}
export {
    GetDeviceInfo,
    ProjectData,
    report,
    report2,
    report3
}